cap log close

global path = "****"

local name= "mort_tables"  
local date = "052020"
global logname = "$path/`name'_`date'.log"

clear
set more off
cd "$path"
log using "$logname", replace

use "$path/Data/penalty_sample.dta", clear


forval age = 35(5)55 {
gen age_`age'_64 = age_2017 < 65 & age_2017 >= `age'
}

*Table: Mortality by different age cutoffs
estimates clear
eststo clear

cap erase "$path/mortality_age_cutoffs_`date'.ster"
*age restrictions
forval age = 35(5)55{
reg dead1718 treatment if age_`age'_64==1 & notall16==1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/mortality_age_cutoffs_`date'.ster", append
}
*no age restriction
reg dead1718 treatment if notall16==1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/mortality_age_cutoffs_`date'.ster", append


*Table: Effect of Intervention on Mortality - no sample exclusion for prior-year insured
estimates clear
eststo clear
reg dead1718 treatment if age_45_64==1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/mort_no16exclusion_`date'.ster", replace

*Table: Analyses Relating to Potential Exclusion Restriction Violations

estimates clear
eststo clear

*Col 1: prior-year mortality
reg dead16 treatment if notall16==1 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/mortality_main_`date'.ster", replace
*Col 2: Mortality Among Prior-Year Insured
reg dead1718 treatment if notall16 == 0 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/mortality_main_`date'.ster", append
inear_`date'.ster", append


log close

